package com.ttc.ssm.service.admin.impl;

import com.ttc.ssm.mapper.admin.*;
import com.ttc.ssm.po.Customer;
import com.ttc.ssm.service.admin.IndexService;
import org.springframework.beans.factory.annotation.Autowired;

import java.lang.reflect.Array;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by Hui on 2016/8/1.
 */
public class IndexServiceImpl implements IndexService{

    @Autowired
    CompanyMapper companyMapper;

    @Autowired
    CompanyDetailMapper companyDetailMapper;

    @Autowired
    CustomerMapper customerMapper;

    @Autowired
    JobMapper jobMapper;

    @Autowired
    ResumeMapper resumeMapper;

    @Autowired
    AdMapper adMapper;

    @Override
    public int countCompany() throws Exception {
        return companyMapper.countCompany();
    }

    @Override
    public int countCompanyDetail(int status) throws Exception {
        return companyDetailMapper.countCompanyDetail(status);
    }

    @Override
    public int count_customer() throws Exception {
        return customerMapper.count_customer();
    }

    @Override
    public int countJob() throws Exception {
        return jobMapper.countJob();
    }

    @Override
    public int countConfirmingJob(int status) throws Exception {
        return jobMapper.countConfirmingJob(status);
    }

    @Override
    public int countResume() throws Exception {
        return resumeMapper.countResume();
    }

    @Override
    public int countAd() throws Exception {
        return adMapper.countAd();
    }

    @Override
    public Map countCompanyByMonth() throws Exception {
        Date now = new Date();
        SimpleDateFormat format = new SimpleDateFormat("MM");
        SimpleDateFormat format1 = new SimpleDateFormat("yyyy");
        int month = Integer.parseInt(format.format(now));
        int year = Integer.parseInt(format1.format(now));
        Calendar cal = Calendar.getInstance();
        Map map = new HashMap();
        Map map1 = new HashMap();
        Map months = new HashMap();
        months.put(1,"JAN");
        months.put(2,"FEB");
        months.put(3,"MAR");
        months.put(4,"APR");
        months.put(5,"MAY");
        months.put(6,"JUN");
        months.put(7,"JUL");
        months.put(8,"AUG");
        months.put(9,"SEP");
        months.put(10,"OCT");
        months.put(11,"NOV");
        months.put(12,"DEC");
        for(int i = 0; i < 12; i++){
            if(month <= 0) {
                month = 12 + month;
                year--;
            }
            cal.set(Calendar.YEAR,year);
            cal.set(Calendar.MONTH, month-1);
            cal.set(Calendar.DAY_OF_MONTH, 1);
            cal.set(Calendar.HOUR_OF_DAY,0);
            cal.set(Calendar.MINUTE,0);
            cal.set(Calendar.SECOND,0);
            Date month_start = cal.getTime();
            cal.set(Calendar.MONTH, month);
            cal.set(Calendar.HOUR_OF_DAY,23);
            cal.set(Calendar.MINUTE,59);
            cal.set(Calendar.SECOND,59);
            cal.set(Calendar.DAY_OF_MONTH, 0);
            Date month_end = cal.getTime();
            int count = companyMapper.countCompanyByMonth(month_start,month_end);
            map.put(i,count);
            map1.put(i,months.get(month)+" "+year);
            month--;
        }
        Map total = new HashMap();
        total.put("y",map);
        total.put("x",map1);
        return total;
    }

    @Override
    public Map countCustomerByMonth() throws Exception {
        Date now = new Date();
        SimpleDateFormat format = new SimpleDateFormat("MM");
        SimpleDateFormat format1 = new SimpleDateFormat("yyyy");
        int month = Integer.parseInt(format.format(now));
        int year = Integer.parseInt(format1.format(now));
        Calendar cal = Calendar.getInstance();
        Map map = new HashMap();
        Map map1 = new HashMap();
        Map months = new HashMap();
        months.put(1,"JAN");
        months.put(2,"FEB");
        months.put(3,"MAR");
        months.put(4,"APR");
        months.put(5,"MAY");
        months.put(6,"JUN");
        months.put(7,"JUL");
        months.put(8,"AUG");
        months.put(9,"SEP");
        months.put(10,"OCT");
        months.put(11,"NOV");
        months.put(12,"DEC");
        for(int i = 0; i < 12; i++){
            if(month <= 0) {
                month = 12 + month;
                year--;
            }
            cal.set(Calendar.YEAR,year);
            cal.set(Calendar.MONTH, month-1);
            cal.set(Calendar.DAY_OF_MONTH, 1);
            cal.set(Calendar.HOUR_OF_DAY,0);
            cal.set(Calendar.MINUTE,0);
            cal.set(Calendar.SECOND,0);
            Date month_start = cal.getTime();
            cal.set(Calendar.MONTH, month);
            cal.set(Calendar.HOUR_OF_DAY,23);
            cal.set(Calendar.MINUTE,59);
            cal.set(Calendar.SECOND,59);
            cal.set(Calendar.DAY_OF_MONTH, 0);
            Date month_end = cal.getTime();
            int count = customerMapper.countCustomerByMonth(month_start,month_end);
            map.put(12-i,count);
            map1.put(12-i,months.get(month)+" "+year);
            month--;
        }
        Map total = new HashMap();
        total.put("y",map);
        total.put("x",map1);
        return total;
    }


}
